package com.lxblyw.service;

import java.util.List;

import com.lxblyw.entity.Task;
import com.lxblyw.dao.GoalDao;
import com.lxblyw.dao.TaskDao;
import com.lxblyw.entity.Goal;

public class GoalService {
	
	private TaskDao taskDao = new TaskDao();
	private GoalDao goalDao = new GoalDao();
	public List<Goal> list(String employeeid, String projectid) {
		return goalDao.findAllById(employeeid,projectid);
	}
	public void save(Goal goal) {
		goalDao.save(goal);
	}
	public void update(String name, String desc, String id) {
		goalDao.update(name,desc,id);
	}
	public Goal get(String goalid) {
		return goalDao.findById(goalid);
	}
	public int updateRate(String id) {
		Goal goal = goalDao.findById(id);
		List<Task> taskList = taskDao.findByGoalId(goal.getId());
		int num = taskList.size();
		
		int totalRate = 0;
		for(Task task : taskList) {
			System.out.println(task.getRate());
			totalRate += Integer.parseInt(task.getRate());
		}
		System.out.println(totalRate);
		System.out.println(num);
		int goalRate = totalRate;
		
		System.out.println(goalRate);
		goalDao.updateRate(id,goalRate/num);
		return goalRate/num;
	}

}
